<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>


<script>
    function updateCourseTable() {
        const week = document.getElementById('week').value;
        fetch('StudentServlet?week=' + week)
            .then(response => response.json())
            .then(data => {
                const rows = data.map(course => {
                    const courseDate = course.courseDate.split(' ')[0];
                    return `<tr><td>${courseDate == '周一'? course.courseName : ''}</td><td>${courseDate == '周二'? course.courseName : ''}</td><td>${courseDate== '周三'? course.courseName : ''}</td><td>${courseDate == '周四'? course.courseName : ''}</td><td>${courseDate == '周五'? course.courseName : ''}</td><td>${courseDate == '周六'? course.courseName : ''}</td><td>${courseDate == '周日'? course.courseName : ''}</td></tr>`;
                }).join('');
                document.querySelector('#courseTable tbody').innerHTML = rows;
            });
    }
</script>

<div class="row search" >
    <div class="col-md-6">
        <form action="${pageContext.request.contextPath}/student?action=schedule" method="post">
            <div class="input-group" style="width: 300px">
                <input type="text" class="form-control" name="c_courseDate"  value="${c_course.courseDate }" placeholder="请输入要查询的星期几...">
                <span class="input-group-btn">
		        <button class="btn btn-default" type="submit"><span class="glyphicon glyphicon-search"></span>&nbsp;查询</button>
		      </span>
            </div>
        </form>
    </div>

    <div>
        <table class="table table-hover  table-bordered table-striped" style="margin-bottom: 0px;">
            <tr>
                <th>序号</th>
                <th>课程名称</th>
                <th>学分</th>
                <th>授课老师</th>
                <th>开课学院</th>
                <th>课程介绍</th>
                <th>选课时间</th>
                <th>开课日期</th>
                <th>开课周数</th>

            </tr>
            <c:forEach var="course" items="${courseList }" varStatus="status">
                <tr>
                    <td>${status.index+1 }</td>
                    <td>${course.courseName }</td>
                    <td>${course.credit }</td>
                    <td>${course.teacherId }</td>
                    <td>${course.department }</td>
                    <td>${course.introduction }</td>
                    <td>${course.checkTime }</td>
                    <td>${course.courseDate }</td>
                    <td>${course.courseWeek }</td>
                </tr>
            </c:forEach>
        </table>
        <nav >
            <ul class="pagination">
                ${pageCode }
            </ul>
        </nav>
    </div>
</div>